<template>
  <div>
    <el-dialog
      :title=title[type]
      :visible.sync="isshow"
      width="500px"
    >
      <el-input
          v-input-restrict v-model="surveyName" :placeholder=placeholder[type]></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="confirm"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  confirmQuestion,
} from "../../../api/questions/updatequestion";
export default {
  name: "MixedStateAdminSurveyName",
  props:{
    //1:新增问卷  2:复制问卷
    type:{
      type: [String,Number],
      default:'1'
    },
    isshow:{
      type: [Boolean],
      default:false
    },
  },
  data() {
    return {
      id:"",
      surveyName:"",
      placeholder:{
        1:'请输入新增问卷标题',
        2:'请输入复制后的问卷标题'
      },
      title:{
        1:'新增问卷',
        2:'复制问卷'
      }
    };
  },

  mounted() {},

  methods: {
    show(id){
      this.surveyName=''
      if (id){
        this.id=id
      }
    },
    confirm(){
      if (!this.surveyName){
        this.$modal.msgWarning('请填写问卷标题')
        return
      }
      //type==2 说明是复制文卷
      if(this.type==2){
        this.$emit('copySurvey',this.surveyName)
      }else {
        confirmQuestion({ id: this.id, surveyName: this.surveyName }).then(res => {
          this.$emit("update:isshow", false);
          this.$router.push({
            path: '/question/addQuestion',
            query: {
              id: this.id
            }
          })
        })
      }
    },
    close(){
      this.$emit("update:isshow", false);
    }
  },
};
</script>

<style lang="scss" scoped>
</style>
